package com.koc.robot;

public class LevelButton 
{
	private float x;
	private float y;
	private String text;
	private int i;
	private boolean unlocked;
	private float value;
	private float textwidth;
	private float coinwidth;
	private boolean active;
	private float xt;
	
	private float xmargin;
	private float textyplus;
	
	private float height;
	private float width;
	
	public LevelButton(float x, float y, String text, int i, boolean unlocked)
	{
		this.x = x;
		this.y = y;
		this.text = text;
		this.i = i;
		this.unlocked = unlocked;
		this.value = 0;
		this.textwidth = Global.levelselectfont.getWidth(this.text);
		this.coinwidth = 0;
		this.active = true;
		this.xt = x;
		
		this.xmargin = 20;
		this.textyplus = -5;
		
		this.height = 80;
		this.width = 190;
	}
	
	public void render()
	{
		if (this.x < -this.width / 2 - 32 || this.x > Global.screenwidth + this.width / 2)
		{
			return;
		}
		
		// TODO: unlocked state
		if (this.unlocked)
		{
			
		}
		else
		{
			float r = 200.0f / 255.0f, g = 200.0f / 255.0f, b = 200.0f / 255.0f;
			GraphicsHelper.setFont(Global.levelselectfont);
			GraphicsHelper.setColor(r, g, b, (100.0f / 255.0f) * Global.fadecolor);
			GraphicsHelper.rectangle(DrawMode.DRAW_FILL, this.x - this.width / 2, this.y, this.width, 30);
			GraphicsHelper.setColor(0, 0, 0, 1.0f * Global.fadecolor);
			if (this.text != null)
			{
				GraphicsHelper.print(this.text, this.x - this.textwidth / 2 + 6, this.y - 2);
			}
			
			GraphicsHelper.setColor(100.0f / 255.0f, 100.0f / 255.0f, 100.0f / 255.0f, 100.0f / 255.0f * Global.fadecolor);
			GraphicsHelper.draw(Global.coinsbackimg, this.x + this.width / 2, this.y);
			
			GraphicsHelper.setColor(r, g, b, 100.0f / 255.0f * Global.fadecolor);
			GraphicsHelper.rectangle(DrawMode.DRAW_FILL, Math.round(this.x - this.width / 2), Math.round(this.y), this.width + 2, this.height + 2);
		}
	}
	
	public void mousepressed(float x, float y)
	{
		if (this.unlocked && this.active)
		{
			if (this.gethighlight(x, y))
			{
				// TODO: start level logic
			}
		}
	}
	
	public boolean gethighlight(float x, float y)
	{
		if ((x >= this.x - this.width / 2 - 1) && (x < this.x + this.width / 2 + 2 + 30) &&
			(y >= this.y - 1) && (y < this.y + this.height + 2))
		{
			return true;
		}
		return false;
	}
}
